<template>
  <!-- 个人信息 -->
  <div class="bf-commont-template">
    <!-- <el-card class="box-card"> -->
      <div slot="header" class="clearfix">
        <div class="clearfix card-slot">
          <div class="float-l">
            <span class="bar-l"></span><span>基本信息</span>
          </div>
          <div class="float-r">
            <!-- <el-button class="car-action" type="text" @click="baseInfoStatus = !baseInfoStatus">编辑</el-button> -->
          </div>
        </div>
      </div>
      <div :class="baseInfoStatus?'input-border-b':'input-border-none'" class="relative">
        <!-- <div :class="baseInfoStatus?'':'mask'"></div> -->

        <div v-if="!baseInfoStatus" class="roster-inner-detail">
          <div class="clearfix relative">
            <div v-for="item in personinfoSetting" :key="item.field" class="clearfix">
              <div class="lable"><span>{{item.title}}</span></div>
              <div class="value">
                <span v-if="!item.isParams">{{form[item.field]}}</span>
                <span v-if="item.isParams"> <span v-params="{code: item.paramsId, id: form[item.field]}"></span></span>
              </div>
            </div>

            <div class="one-action">
              <div @click="baseInfoStatus = !baseInfoStatus" class="color"><img src="../../../../../../assets/beneform4j/roster/roster_icon_edit.png" alt=""><span>编辑</span></div>
            </div>
          </div>
        </div>
        <div  v-if="baseInfoStatus" class="int-content clearfix rp-content inner">
          <el-form
            ref="form"
            :model="form"
            :rules="editRules"
            label-width="137px"
            :label-position="'right'"
            class="clearfix">
            <div
              v-for="item in personinfoSetting"
              :key="item.field"
              v-if="!item.hideEdit"
              class="bf-table-form-item padding-l padding-r">
              <component
                v-if="!item.slot"
                v-bind:is="'bf-form-'+item.type"
                :form="form"
                :item="item"
                :disabled="item.disableEdit"
                :rules="editRules">
              </component>
            </div>
          </el-form>

          <div class="w-100" :hidden="!baseInfoStatus">
            <div class="w-12"></div>
            <div>
              <el-button type="primary" @click="savePersionInfo(form)">保存</el-button>
              <el-button  @click="baseInfoStatus=false">取消</el-button>
            </div>
          </div>
        </div>
      </div>
    <!-- </el-card> -->
    <div class="gap"></div>

    <!-- <el-card class="box-card"> -->
      <div slot="header" class="clearfix">
        <!-- <span>教育经历</span> -->
        <div class="clearfix card-slot">
          <div class="float-l">
            <span class="bar-l"></span><span>教育经历</span>
          </div>
          <div class="float-r">
            <el-button class="car-action" type="text" @click="addEducation">新增</el-button>
          </div>
        </div>
      </div>
      <div>
          <div v-if="education.length == 0" class="data-null">
            <img src="../../../../../../assets/beneform4j/roster/icon_not_record.png" alt="">
            <div class="text-c">
              <span>
                暂无教育经历
              </span>
            </div>
          </div>
          <div  v-for="item in education" :key="item.id"  :class="item._editing?'form-editing input-border-b':'form-edited input-border-none'">
            <div class="int-content clearfix rp-content relative inner">
              <!-- <div :class="item._editing?'':'mask'"></div> -->
              <div>
                <div>学历:</div>
                <div>
                  <!-- <el-input v-model="item.education" v-if="item._editing"></el-input> -->

                  <el-select v-model="item.education" placeholder="请选择" v-if="item._editing">
                    <el-option
                      v-for="item in educationOptions"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value">
                    </el-option>
                  </el-select>

                  <div class="int-iput-value"  v-if="!item._editing"><span >{{customEducation(item.education)}}</span></div>
                </div>
              </div>
              <div>
                <div>毕业院校:</div>
                <div>
                  <el-input v-model="item.graduationSchool" v-if="item._editing"></el-input>
                  <div class="int-iput-value"  v-if="!item._editing"><span >{{item.graduationSchool}}</span></div>
                </div>
              </div>
              <div>
                <div>毕业时间:</div>
                <div>
                  <!-- <el-input v-model="item.graduationDate" v-if="item._editing"></el-input> -->
                  <el-date-picker
                    v-if="item._editing"
                    v-model="item.graduationDate"
                    type="date"
                    format="yyyy-MM-dd"
                    value-format="yyyy-MM-dd"
                    placeholder="选择日期">
                  </el-date-picker>
                  <div class="int-iput-value"  v-if="!item._editing"><span >{{item.graduationDate}}</span></div>
                </div>
              </div>
              <div>
                <div>毕业专业:</div>
                <div>
                  <el-input v-model="item.graduationMajor" v-if="item._editing"></el-input>
                  <div class="int-iput-value"  v-if="!item._editing"><span >{{item.graduationMajor}}</span></div>
                </div>
              </div>

              <div>
                <div>毕业证书编号:</div>
                <div>
                  <el-input v-model="item.diplomaNumber" v-if="item._editing"></el-input>
                  <div class="int-iput-value"  v-if="!item._editing"><span >{{item.diplomaNumber}}</span></div>
                </div>
              </div>
              <div>
                <div>学位:</div>
                <div>
                  <el-input v-model="item.academicDegree" v-if="item._editing"></el-input>
                  <div class="int-iput-value"  v-if="!item._editing"><span >{{item.academicDegree}}</span></div>
                </div>
              </div>
              <div>
                <div>学位证书编号:</div>
                <div>
                  <el-input v-model="item.certificateNumber" v-if="item._editing"></el-input>
                  <div class="int-iput-value"  v-if="!item._editing"><span >{{item.certificateNumber}}</span></div>
                </div>
              </div>
              <div>
                <div>是否为最高学历:</div>
                <div>
                  <el-input v-model="item.highEducationFlag" v-if="item._editing"></el-input>
                  <div class="int-iput-value"  v-if="!item._editing"><span >{{item.highEducationFlag}}</span></div>
                </div>
              </div>
              <div>
                <div>学习形式:</div>
                <div>
                  <el-input v-model="item.learningForm" v-if="item._editing"></el-input>
                  <div class="int-iput-value"  v-if="!item._editing"><span >{{item.learningForm}}</span></div>
                </div>
              </div>
              <div >
                <div >备注:</div>
                <div>
                  <el-input v-model="item.reamarks" v-if="item._editing"></el-input>
                  <div class="int-iput-value"  v-if="!item._editing"><span >{{item.reamarks}}</span></div>
                </div>
              </div>
              <!-- <div class="w-100">
                <div >附件:</div>
                <div>
                  <el-input v-model="item.h" v-if="item._editing"></el-input>
                  <div class="int-iput-value"  v-if="!item._editing"><span >{{item.h}}</span></div>
                </div>
              </div> -->
              <div class="w-100" v-if="item._editing">
                <div class="action-button">
                  <el-button type="primary" @click="saveEduction(item)">保存</el-button>
                  <!-- <el-button type="primary" @click="editEduction(item)">编辑</el-button> -->
                  <!-- <el-button type="primary" @click="deleteEduction(item)">删除</el-button> -->
                  <el-button @click="item._editing = false; deleteEduction(item, true)">取消</el-button>
                </div>
              </div>

              <div class="list-edit" v-if="!item._editing">
                <div @click="editEduction(item)"><img src="../../../../../../assets/beneform4j/roster/roster_icon_edit.png" alt=""><span>编辑</span></div>
              </div>
              <div class="list-delete" v-if="item._editing">
                <div  @click="deleteEduction(item)"><img src="../../../../../../assets/beneform4j/roster/roster_icon_delete.png" alt=""><span>删除</span></div>
              </div>
            </div>
          </div>
      </div>
    <!-- </el-card> -->
    <div class="gap"></div>

    <!-- <el-card class="box-card"> -->
      <div slot="header" class="clearfix">
        <!-- <span>工作经历</span> -->
        <div class="clearfix card-slot">
          <div class="float-l">
            <span class="bar-l"></span><span>工作经历</span>
          </div>
          <div class="float-r">
            <el-button class="car-action" type="text" @click="addWorkCareer">新增</el-button>
          </div>
        </div>
      </div>
      <div>
          <div v-if="workCareer.length == 0" class="data-null">
            <img src="../../../../../../assets/beneform4j/roster/icon_not_record.png" alt="">
            <div class="text-c">
              <span>
                暂无工作经历
              </span>
            </div>
          </div>
          <div  v-for="item in workCareer" :key="item.id"  :class="item._editing?'form-editing input-border-b':'form-edited input-border-none'">
            <div class="int-content clearfix rp-content relative inner">
              <!-- <div :class="item._editing?'':'mask'"></div> -->
              <div>
                <div>工作单位:</div>
                <div>
                  <el-input v-model="item.workCompany" v-if="item._editing"></el-input>
                  <div class="int-iput-value"  v-if="!item._editing"><span >{{item.workCompany}}</span></div>
                </div>
              </div>
              <div>
                <div>职务:</div>
                <div>
                  <el-input v-model="item.position"  v-if="item._editing"></el-input>
                  <div class="int-iput-value"  v-if="!item._editing"><span >{{item.position}}</span></div>
                </div>
              </div>
              <div>
                <div>开始工作时间:</div>
                <div>
                  <!-- <el-input v-model="item.startDate"  v-if="item._editing"></el-input> -->
                  <el-date-picker
                    v-if="item._editing"
                    v-model="item.startDate"
                    type="date"
                    format="yyyy-MM-dd"
                    value-format="yyyy-MM-dd"
                    placeholder="选择日期">
                  </el-date-picker>
                  <div class="int-iput-value"  v-if="!item._editing"><span >{{item.startDate}}</span></div>
                </div>
              </div>
              <div>
                <div>结束工作时间:</div>
                <div>
                  <!-- <el-input v-model="item.endDate"  v-if="item._editing"></el-input> -->
                  <el-date-picker
                    v-if="item._editing"
                    v-model="item.endDate"
                    type="date"
                    format="yyyy-MM-dd"
                    value-format="yyyy-MM-dd"
                    placeholder="选择日期">
                  </el-date-picker>
                  <div class="int-iput-value"  v-if="!item._editing"><span >{{item.endDate}}</span></div>
                </div>
              </div>
              <div>
                <div>证明人:</div>
                <div>
                  <el-input v-model="item.reterence" v-if="item._editing" ></el-input>
                  <div class="int-iput-value"  v-if="!item._editing"><span >{{item.reterence}}</span></div>
                </div>
              </div>
              <div>
                <div>证明人联系电话:</div>
                <div>
                  <el-input v-model="item.reterenceMobile" v-if="item._editing" ></el-input>
                  <div class="int-iput-value"  v-if="!item._editing"><span >{{item.reterenceMobile}}</span></div>
                </div>
              </div>
              <div>
                <div>离职原因:</div>
                <div>
                  <el-input v-model="item.leaveReason" v-if="item._editing" ></el-input>
                  <div class="int-iput-value"  v-if="!item._editing"><span >{{item.leaveReason}}</span></div>
                </div>
              </div>
              <div class="w-100">
                <div >备注:</div>
                <div>
                  <el-input v-model="item.remarks" v-if="item._editing" ></el-input>
                  <div class="int-iput-value"  v-if="!item._editing"><span >{{item.remarks}}</span></div>
                </div>
              </div>
              <div class="w-100" v-if="item._editing">
                <div class="action-button">
                  <el-button type="primary" @click="saveWorkCareer(item)">保存</el-button>
                  <!-- <el-button type="primary" @click="editWorkCareer(item)">编辑</el-button> -->
                  <!-- <el-button type="primary" @click="deleteWorkCareer(item)">删除</el-button> -->
                  <el-button @click="item._editing = false; deleteWorkCareer(item, true)">取消</el-button>
                </div>
              </div>

              <div class="list-edit" v-if="!item._editing">
                <div @click="editWorkCareer(item)"><img src="../../../../../../assets/beneform4j/roster/roster_icon_edit.png" alt=""><span>编辑</span></div>
              </div>
              <div class="list-delete" v-if="item._editing">
                <div  @click="deleteWorkCareer(item)"><img src="../../../../../../assets/beneform4j/roster/roster_icon_delete.png" alt=""><span>删除</span></div>
              </div>

            </div>
            <!-- <div class="int-content clearfix border-b"> -->

            <!-- </div> -->
          </div>
      </div>
    <!-- </el-card> -->
    <div class="gap"></div>

    <!-- <el-card class="box-card"> -->
      <div slot="header" class="clearfix">
        <!-- <span>证书证件</span> -->
        <div class="clearfix card-slot">
          <div class="float-l">
            <span class="bar-l"></span><span>证书证件</span>
          </div>
          <div class="float-r">
            <el-button class="car-action" type="text" @click="addCertificate">新增</el-button>
          </div>
        </div>
      </div>
      <div>
          <div v-if="certificate.length == 0" class="data-null">
            <img src="../../../../../../assets/beneform4j/roster/icon_not_record.png" alt="">
            <div class="text-c">
              <span>
                暂无证书证件
              </span>
            </div>
          </div>
          <div  v-for="item in certificate" :key="item.id"  :class="item._editing?'form-editing input-border-b':'form-edited input-border-none'">
            <div class="int-content clearfix rp-content relative inner">
              <!-- <div :class="item._editing?'':'mask'"></div> -->
              <div>
                <div>证书/证件类型:</div>
                <div>
                  <el-input v-model="item.certificateType" v-if="item._editing"></el-input>
                  <div class="int-iput-value"  v-if="!item._editing"><span >{{item.certificateType}}</span></div>
                </div>
              </div>
              <div>
                <div>证书名称:</div>
                <div>
                  <el-input v-model="item.certificateName" v-if="item._editing"></el-input>
                  <div class="int-iput-value"  v-if="!item._editing"><span >{{item.certificateName}}</span></div>
                </div>
              </div>
              <div>
                <div>发证机构:</div>
                <div>
                  <el-input v-model="item.issuingAgency" v-if="item._editing"></el-input>
                  <div class="int-iput-value"  v-if="!item._editing"><span >{{item.issuingAgency}}</span></div>
                </div>
              </div>
              <div>
                <div>发证日期:</div>
                <div>
                  <!-- <el-input v-model="item.issuingDate" v-if="item._editing"></el-input> -->
                  <el-date-picker
                    v-if="item._editing"
                    v-model="item.issuingDate"
                    type="date"
                    format="yyyy-MM-dd"
                    value-format="yyyy-MM-dd"
                    placeholder="选择日期">
                  </el-date-picker>
                  <div class="int-iput-value"  v-if="!item._editing"><span >{{item.issuingDate}}</span></div>
                </div>
              </div>
              <div>
                <div>有效期起止日期:</div>
                <div>
                  <!-- <el-input v-model="item.effectStartDate" v-if="item._editing"></el-input> -->
                  <el-date-picker
                    v-if="item._editing"
                    v-model="item.effectStartDate"
                    type="date"
                    format="yyyy-MM-dd"
                    value-format="yyyy-MM-dd"
                    placeholder="选择日期">
                  </el-date-picker>
                  <div class="int-iput-value"  v-if="!item._editing"><span >{{item.effectStartDate}}</span></div>
                </div>
              </div>
              <div>
                <div>有效期截止日期:</div>
                <div>
                  <!-- <el-input v-model="item.effectEndDate" v-if="item._editing"></el-input> -->
                  <el-date-picker
                    v-if="item._editing"
                    v-model="item.effectEndDate"
                    type="date"
                    format="yyyy-MM-dd"
                    value-format="yyyy-MM-dd"
                    placeholder="选择日期">
                  </el-date-picker>
                  <div class="int-iput-value"  v-if="!item._editing"><span >{{item.effectEndDate}}</span></div>
                </div>
              </div>
              <div class="w-100">
                <div >备注:</div>
                <div>
                  <el-input v-model="item.remarks" v-if="item._editing"></el-input>
                  <div class="int-iput-value"  v-if="!item._editing"><span >{{item.remarks}}</span></div>
                </div>
              </div>
              <div class="w-100" v-if="item._editing">
                <div class="action-button">
                  <el-button type="primary" @click="saveCertificate(item)">保存</el-button>
                  <!-- <el-button type="primary" @click="editCertificate(item)">编辑</el-button> -->
                  <!-- <el-button type="primary" @click="deleteCertificate(item)">删除</el-button> -->
                  <el-button @click="item._editing = false; deleteCertificate(item, true)">取消</el-button>
                </div>
              </div>

              <div class="list-edit" v-if="!item._editing">
                <div @click="editCertificate(item)"><img src="../../../../../../assets/beneform4j/roster/roster_icon_edit.png" alt=""><span>编辑</span></div>
              </div>
              <div class="list-delete" v-if="item._editing">
                <div  @click="deleteCertificate(item)"><img src="../../../../../../assets/beneform4j/roster/roster_icon_delete.png" alt=""><span>删除</span></div>
              </div>
            </div>
            <!-- <div class="int-content clearfix border-b">
              <div class="w-100" >
                <div class="w-12"></div>
                <div>
                  <el-button type="primary" @click="saveCertificate(item)">保存</el-button>
                  <el-button type="primary" @click="editCertificate(item)">编辑</el-button>
                  <el-button type="primary" @click="deleteCertificate(item)">删除</el-button>
                  <el-button @click="item._editing = false">取消</el-button>
                </div>
              </div>
            </div> -->
          </div>
      </div>
    <!-- </el-card> -->
    <div class="gap"></div>

    <!-- <el-card class="box-card"> -->
      <div slot="header" class="clearfix">
        <!-- <span>培训经历</span> -->
        <div class="clearfix card-slot">
          <div class="float-l">
            <span class="bar-l"></span><span>培训经历</span>
          </div>
          <div class="float-r">
            <el-button class="car-action" type="text" @click="addTrainCareer">新增</el-button>
          </div>
        </div>
      </div>
      <div>
          <div v-if="trainCareer.length == 0" class="data-null">
            <img src="../../../../../../assets/beneform4j/roster/icon_not_record.png" alt="">
            <div class="text-c">
              <span>
                暂无培训经历
              </span>
            </div>
          </div>
          <div  v-for="item in trainCareer" :key="item.id"  :class="item._editing?'form-editing input-border-b':'form-edited input-border-none'">
            <div class="int-content clearfix rp-content relative inner">
              <!-- <div :class="item._editing?'':'mask'"></div> -->
              <div>
                <div>培训名称:</div>
                <div>
                  <el-input v-model="item.trainName" v-if="item._editing"></el-input>
                  <div class="int-iput-value"  v-if="!item._editing"><span >{{item.trainName}}</span></div>
                </div>
              </div>
              <div>
                <div>培训单位:</div>
                <div>
                  <el-input v-model="item.trainDepart" v-if="item._editing"></el-input>
                  <div class="int-iput-value"  v-if="!item._editing"><span >{{item.trainDepart}}</span></div>
                </div>
              </div>
              <div>
                <div>培训开始日期:</div>
                <div>
                  <!-- <el-input v-model="item.beginDate" v-if="item._editing"></el-input> -->
                  <el-date-picker
                    v-if="item._editing"
                    v-model="item.beginDate"
                    type="date"
                    format="yyyy-MM-dd"
                    value-format="yyyy-MM-dd"
                    placeholder="选择日期">
                  </el-date-picker>
                  <div class="int-iput-value"  v-if="!item._editing"><span >{{item.beginDate}}</span></div>
                </div>
              </div>
              <div>
                <div>培训结束日期:</div>
                <div>
                  <!-- <el-input v-model="item.endDate" v-if="item._editing"></el-input> -->
                  <el-date-picker
                    v-if="item._editing"
                    v-model="item.endDate"
                    type="date"
                    format="yyyy-MM-dd"
                    value-format="yyyy-MM-dd"
                    placeholder="选择日期">
                  </el-date-picker>
                  <div class="int-iput-value"  v-if="!item._editing"><span >{{item.endDate}}</span></div>
                </div>
              </div>

              <div>
                <div>培训成绩:</div>
                <div>
                  <el-input v-model="item.trainAchievement" v-if="item._editing"></el-input>
                  <div class="int-iput-value"  v-if="!item._editing"><span >{{item.trainAchievement}}</span></div>
                </div>
              </div>
              <div>
                <div>培训证书名称:</div>
                <div>
                  <el-input v-model="item.certName" v-if="item._editing"></el-input>
                  <div class="int-iput-value"  v-if="!item._editing"><span >{{item.certName}}</span></div>
                </div>
              </div>
              <div>
                <div>培训证书编号:</div>
                <div>
                  <el-input v-model="item.certNo" v-if="item._editing"></el-input>
                  <div class="int-iput-value"  v-if="!item._editing"><span >{{item.certNo}}</span></div>
                </div>
              </div>
              <div class="w-100">
                <div >备注:</div>
                <div>
                  <el-input v-model="item.remarks" v-if="item._editing"></el-input>
                  <div class="int-iput-value"  v-if="!item._editing"><span >{{item.remarks}}</span></div>
                </div>
              </div>

              <div class="w-100" v-if="item._editing">
                <!-- <div class="w-12"></div> -->
                <div class="action-button">
                  <el-button type="primary" @click="saveTrainCareer(item)">保存</el-button>
                  <!-- <el-button type="primary" @click="editTrainCareer(item)">编辑</el-button> -->
                  <!-- <el-button type="primary" @click="deleteTrainCareer(item)">删除</el-button> -->
                  <el-button @click="item._editing = false; deleteTrainCareer(item, true)">取消</el-button>
                </div>
              </div>

              <div class="list-edit" v-if="!item._editing">
                <div @click="editTrainCareer(item)"><img src="../../../../../../assets/beneform4j/roster/roster_icon_edit.png" alt=""><span>编辑</span></div>
              </div>
              <div class="list-delete" v-if="item._editing">
                <div  @click="deleteTrainCareer(item)"><img src="../../../../../../assets/beneform4j/roster/roster_icon_delete.png" alt=""><span>删除</span></div>
              </div>

            </div>
            <!-- <div class="int-content clearfix border-b">
              <div class="w-100" >
                <div class="w-12"></div>
                <div>
                  <el-button type="primary" @click="saveTrainCareer(item)">保存</el-button>
                  <el-button type="primary" @click="editTrainCareer(item)">编辑</el-button>
                  <el-button type="primary" @click="deleteTrainCareer(item)">删除</el-button>
                  <el-button @click="item._editing = false">取消</el-button>
                </div>
              </div>
            </div> -->
          </div>
      </div>
    <!-- </el-card> -->
    <div class="gap"></div>

  </div>
</template>

<script>
import { getSelected } from '../../../../../api/common'
import { otherBaseInfoApi, getEmployeeInfoApi, deleteCertificateApi, addCertificateApi, editCertificateApi, getCertificateApi, deleteTrainCareerApi, addTrainCareerApi, editTrainCareerApi, getTrainCareerApi, deleteExperiencesApi, addExperiencesApi, editExperiencesApi, getExperiencesApi, getEducationApi, addEducationApi, editEducationApi, deleteEducationApi } from '../api'
import { personinfoSetting } from './form'
export default {
  props: ['employeeData'],
  data() {
    return {
      educationOptions: [],
      editRules: {},
      personinfoSetting: personinfoSetting,
      form: {},
      employeeDataCp: {},
      employeeNo: '',
      baseInfoStatus: false,
      education: [ // 教育经历
        {
          _editing: false
        }
      ],
      workCareer: [ // 工作经历
        {
          _editing: false
        }
      ],
      certificate: [ // 证书证件
        {
          _editing: false
        }
      ],
      trainCareer: [ // 培训经历
        {
          _editing: false
        }
      ]
    }
  },
  mounted: function() {
    this.employeeNo = this.employeeData.employeeNo
    // 获取教育经历信息
    this.getEducation()
    // 获取工作经历
    this.getExperiences()
    // 获取培训经历
    this.getTrainCareerApi()
    // 获取证书证件
    this.getCertificate()
    // 获取员工信息
    this.getJobInfo()
    this.getSelectedEducationOptions()
  },
  methods: {
    customEducation(code) {
      const len = this.educationOptions.length
      for (let i = 0; i < len ;i++) {
        const item = this.educationOptions[i]
        if (item.value === code) {
          return item.label
        }
      }
    },
    getSelectedEducationOptions() {
      getSelected('EDUCATION').then(response => {
        if (response.success) {
          if (response.data) {
            this.educationOptions = []
            response.data.items.forEach(v => {
              const obj = {
                value: v.itemCode,
                label: v.itemText
              }
              this.educationOptions.push(obj)
            })
          }
        }
      })
    },
    getJobInfo() {
      getEmployeeInfoApi(this.employeeNo).then(response => {
        this.employeeDataCp = response.data
        this.form = response.data
      })
    },
    deleteCertificate(item, status) {
      if (item._add === true) {
        this.certificate.forEach((v, i) => {
          if (v == item) {
            this.certificate.splice(i, 1)
          }
        })
        return
      }
      if (status) {
        return
      }
      deleteCertificateApi(item).then(response => {
        if (response.success) {
          this.$message({
            message: '删除证书证件成功',
            type: 'success'
          })
          item._editing = false
          this.getCertificate()
        }
      })
    },
    editCertificate(item) {
      this.$set(item, '_editing', true)
    },
    saveCertificate(form) {
      form.employeeNo = this.employeeNo
      if (form._add) {
        // 新增
        addCertificateApi(form).then(response => {
          if (response.success) {
            this.$message({
              message: '添加证书证件成功',
              type: 'success'
            })
            form._add = false
            form._editing = false
            this.getCertificate()
          }
        })
      } else {
        // 编辑
        editCertificateApi(form).then(response => {
          if (response.success) {
            this.$message({
              message: '修改证书证件成功',
              type: 'success'
            })
            form._add = false
            form._editing = false
            this.getCertificate()
          }
        })
      }
    },
    getCertificate() {
      getCertificateApi(this.employeeNo).then(response => {
        this.certificate = response.data
      })
    },
    deleteTrainCareer(item, status) {
      if (item._add === true) {
        this.trainCareer.forEach((v, i) => {
          if (v == item) {
            this.trainCareer.splice(i, 1)
          }
        })
        return
      }
      if (status) {
        return
      }
      deleteTrainCareerApi(item).then(response => {
        if (response.success) {
          this.$message({
            message: '删除培训经历修改成功',
            type: 'success'
          })
          item._editing = false
          this.getTrainCareerApi()
        }
      })
    },
    editTrainCareer(item) {
      this.$set(item, '_editing', true)
    },
    saveTrainCareer(form) {
      form.employeeNo = this.employeeNo
      if (form._add) {
        // 新增
        addTrainCareerApi(form).then(response => {
          if (response.success) {
            this.$message({
              message: '添加培训经历成功',
              type: 'success'
            })
            form._add = false
            form._editing = false
            this.getTrainCareerApi()
          }
        })
      } else {
        // 编辑
        editTrainCareerApi(form).then(response => {
          if (response.success) {
            this.$message({
              message: '修改培训经历成功',
              type: 'success'
            })
            form._add = false
            form._editing = false
            this.getTrainCareerApi()
          }
        })
      }
    },
    getTrainCareerApi() {
      getTrainCareerApi(this.employeeNo).then(response => {
        this.trainCareer = response.data
      })
    },
    editWorkCareer(item) {
      this.$set(item, '_editing', true)
    },
    deleteWorkCareer(item, status) {
      if (item._add === true) {
        this.workCareer.forEach((v, i) => {
          if (v == item) {
            this.workCareer.splice(i, 1)
          }
        })
        return
      }
      if (status) {
        return
      }
      deleteExperiencesApi(item).then(response => {
        if (response.success) {
          this.$message({
            message: '删除工作经历修改成功',
            type: 'success'
          })
          item._editing = false
          this.getExperiences()
        }
      })
    },
    saveWorkCareer(form) {
      form.employeeNo = this.employeeNo
      if (form._add) {
        // 新增
        addExperiencesApi(form).then(response => {
          if (response.success) {
            this.$message({
              message: '添加工作经历成功',
              type: 'success'
            })
            form._add = false
            form._editing = false
            this.getExperiences()
          }
        })
      } else {
        // 编辑
        editExperiencesApi(form).then(response => {
          if (response.success) {
            this.$message({
              message: '修改工作经历成功',
              type: 'success'
            })
            form._add = false
            form._editing = false
            this.getExperiences()
          }
        })
      }
    },
    getExperiences() {
      getExperiencesApi(this.employeeNo).then(response => {
        this.workCareer = response.data
      })
    },
    saveEduction(form) {
      // console.log(form)
      form.employeeNo = this.employeeNo
      if (form._add) {
        addEducationApi(form).then(response => {
          // console.log(response)
          if (response.success) {
            this.$message({
              message: '添加教育经历成功成功',
              type: 'success'
            })
            form._add = false
            form._editing = false
            this.getEducation()
          }
        })
      } else {
        // console.log(form)
        editEducationApi(form).then(response => {
          if (response.success) {
            this.$message({
              message: '教育经历修改成功',
              type: 'success'
            })
            form._editing = false
            this.getEducation()
          }
        })
      }
    },
    getEducation() {
      getEducationApi(this.employeeNo).then(response => {
        this.education = response.data
      })
    },
    addTrainCareer() {
      // console.log('添加培训经历')
      this.trainCareer.unshift({
        _editing: true,
        _add: true
      })
    },
    addCertificate() {
      this.certificate.unshift({
        _editing: true,
        _add: true
      })
    },
    addWorkCareer() {
      // console.log('添加工作经历')
      this.workCareer.unshift({
        _editing: true,
        _add: true
      })
    },
    addEducation() {
      // console.log('添加教育经历')
      this.education.unshift({
        _editing: true,
        _add: true
      })
    },
    editEduction(item) {
      // console.log(item)
      this.$set(item, '_editing', true)
    },
    deleteEduction(item, status) {
      // console.log(item)
      if (item._add === true) {
        this.education.forEach((v, i) => {
          if (v == item) {
            this.education.splice(i, 1)
          }
        })
        return
      }
      if (status) {
        return
      }
      deleteEducationApi(item).then(response => {
        if (response.success) {
          this.$message({
            message: '删除教育经历修改成功',
            type: 'success'
          })
          item._editing = false
          this.getEducation()
        }
      })
    },
    savePersionInfo(form) {
      // editJobInfoApi(form).then(response => {
      //   if (response.success) {
      //     this.$message({
      //       message: '员工基本修改成功',
      //       type: 'success'
      //     })
      //     this.baseInfoStatus = false
      //     this.getJobInfo()
      //   }
      // })
      otherBaseInfoApi(form).then(response => {
        if (response.success) {
          this.$message({
            message: '员工基本修改成功',
            type: 'success'
          })
          this.baseInfoStatus = false
          this.getJobInfo()
        }
      })
    }
  }
}
</script>

<style scoped>

@import './form.css';
</style>
